const Router = require("koa-router");
const {
  getQuestionById,
  getQuestionList,
  createQuestion,
  editQuestion,
  editQuestionList,
  deleteQuestionList,
  duplicateQuestion,
  getQuestionStatListById,
  getQuestionComponentStatById,
  getPublishedQuestionById,
  createQuestionAnswer,
  getUsageInfo,
  deleteAnswerById,
} = require("../controller/question.controller");
const { auth } = require("../middleware/auth.middleware");
const router = new Router({ prefix: "/api/question" });

// 获取问卷列表
router.get("/list", auth, getQuestionList);

// 根据id获取问卷信息
router.get("/info/:questionId", auth, getQuestionById);

// 新增问卷
router.post("/", auth, createQuestion);

// 编辑问卷
router.patch("/edit/:questionId", auth, editQuestion);

// 批量编辑问卷
router.post("/edit", auth, editQuestionList);

// 批量彻底删除问卷
router.delete("/", auth, deleteQuestionList);

// 复制问卷
router.post("/duplicate/:questionId", auth, duplicateQuestion);

// 根据id获取问卷的统计信息
router.get("/stat/:questionId", auth, getQuestionStatListById);

// 根据id获取问卷单个组件的统计信息
router.get(
  "/stat/:questionId/:componentId",
  auth,
  getQuestionComponentStatById
);

// 根据id获取已发布的问卷信息
router.get("/published/:questionId", getPublishedQuestionById);

// 答卷
router.post("/answer/:questionId", createQuestionAnswer);

// 删除答卷记录
router.delete("/stat/:questionId/:answerId", auth, deleteAnswerById);

// 获取使用统计信息
router.get("/usage", getUsageInfo);

module.exports = router;
